let Koa = require('koa');
let Router = require('koa-router');
let Views = require('koa-views');
let Serve = require('koa-static');
let app = new Koa();

const router = new Router();

router
    .get( '/', async ( ctx, next) => {
        ctx.redirect('/index');
        ctx.status = 301;
    })
    .get( '/index', async ( ctx, next) => {
        await ctx.render('index.html');
    })
    .get( '/main', async ( ctx, next) => {
        await ctx.render('main.html');
    });

app
    .use( Serve( __dirname + '/static'))
    .use( Views( __dirname + '/views'), {
        map: {
            html: 'nunjucks'
        }
    })
    .use( ( ctx, next)=>{
        console.log('ctx', ctx);
        console.log('next', next);
        return next();
    })
    .use( router.routes())
    .use( router.allowedMethods());

app.listen( 3000);
console.log('请打开 http://localhost:3000!');